package edu.ahut.corejava;

import java.io.IOException;
import java.util.Arrays;

public class ExceptionDemo {
    public static void main(String[] args) {
        int[] a = {1, 2, 3};

        try {
            a[3]++;//ArrayIndexOutOfBoundsException
            Object b = null;
            System.out.println(b.hashCode());//NullPointerException
        } catch (ArrayIndexOutOfBoundsException e) {
            int[] b = new int[a.length * 2];//倍增算法
            for (int i = 0; i < a.length; i++) {
                b[i] = a[i];
            }
            a = b;//
            a[3]++;

        } catch (NullPointerException e) {

        } finally {
            System.out.println("close database connection");
        }
        System.out.println(Arrays.toString(a));

        try {
            Runtime.getRuntime().exec("notepad.exe");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
